<?php 

session_start();
if (!isset ($_SESSION["id"])) {
	session_destroy();
	echo "<script language='javascript'>top.location.href = 'Login.php';</script>";
	exit;
}

include_once 'public/DB_Oracle.php';
include_once 'public/page/page.class.php';
$t_u=$_SERVER['PHP_SELF'];
$t_u=explode('/',$t_u);
$this_url = end($t_u);


$rbox_array=array(array("001.gif","POP('POPdiv')","新增"),array("010.gif","delChecked()","批量删除"));
$rclo_array=array(array("037.gif","editRow","修改"),array("010.gif","delRow","删除"));
$rbox=array();
$waring_array=array('r'=>'请输入日期！','n'=>'请输入数字！');
$columns=array(
	array('ID','REF_ID'),
	array('车牌号','CAR_ID'),
	array('油品种类','OIL_TYPE'),
	array('加油时间','REF_TIME','r'),
	array('金额','REF_SUM','n'),
	array('单价','UNIT_PRICE','n'),
	array('油量','REF_OIL','n'),
	array('出车单号','OUT_CAR_NUMB')
		);
;
$rcol=array(0,1);
$title="加油表";

//序号对应列
$add_array=array(
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21
);
$edit_array=array(
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21
);


$DBsql = new DB_Oracle ();
$querytab=0;
if(isset($_GET['querytab'])){
$query=$_GET['querytab'];
}
$table='GPS_COST_REFUEL';
switch($querytab)
{
	case 0;
	$table='GPS_COST_REFUEL';
	//$columns=array('ID','车牌号','油品种类','加油时间','金额','单价','油量','出车单号');
	break;	
	case 1;
	$table='GPS_COST_REFUEL';
	//$columns=array('ID','车牌号','油品种类','加油时间','金额','单价','油量','出车单号');
	break;
	case 2;
	$table='GPS_COST_REFUEL';
	break;
	case 3;
	$table='GPS_COST_EXPENSE';
	$columns=array(
	array('ID','ID'),
	array('车牌号','CAR_ID'),
	array('时间','XF_TIME','r'),
	array('杂支类型','ZC_TYPE'),
	array('金额','MONEY','n'),
	array('出车单','OUT_CAR_NUMB'),
	array('备注说明','REMARK')
		);
	$title='杂支表';
	break;
	case 4;
	$table='GPS_COST_MAINTENANCE';
	$columns=array(
	array('ID','ID'),
	array('车牌号','CAR_ID'),
	array('时间','BY_TIME','r'),
	array('行驶里程','MILEAGE','n'),
	array('金额','SUM','n'),
	array('联系人','CONTACT'),
	array('联系电话','PHONE'),
	array('维修地点','ADDRESS'),
	array('出车单','OUT_CAR_NUMB'),
	array('备注','REMARK')
		);
	$title='保养表';
	break;
	case 5;
	$table='GPS_COST_SERVICE';
	$columns=array(
	array('ID','ID'),
	array('车牌号','CAR_ID'),
	array('时间','WX_TIME','r'),
	array('个人出钱','GR_MONEY','n'),
	array('保险出钱','BX_MONEY','n'),
	array('公司出钱','GS_MONEY','n'),
	array('联系人','CONTACT'),
	array('联系电话','PHONE'),
	array('维修地点','ADDRESS'),
	array('出车单','OUT_CAR_NUMB'),
	array('备注','REMARK')
	);
	$title='维修表';
	break;
	case 6;
	$table='GPS_COST_SAFETY';
	$columns=array(
	array('ID','ID'),
	array('车牌号','CAR_ID'),
	array('开始时间','START_TIME','r'),
	array('结束时间','END_TIME','r'),
	array('保险公司','BX_NAME'),
	array('保险种类','BX_TYPE'),
	array('金额','MONEY','n'),
	array('备注','REMARK')
	);
	$title='保险表';
	break;
	case 7;
	$table='GPS_COST_OVERHAUL';
	$columns=array(
	array('ID','ID'),
	array('车牌号','CAR_ID'),
	array('开始时间','START_TIME','r'),
	array('结束时间','END_TIME','r'),
	array('代办人','DB_CONTACT'),
	array('联系电话','PHONE'),
	array('金额','MONEY','n'),
	array('备注','REMARK')
	);
	$title='年检表';
	break;
	default:
	$table='GPS_COST_REFUEL';
	break;
}
$search='';
$sw='';
if(isset($_GET['search']))
{
	$search=$_GET['search'];
	//构建where条件循环
	$sw=' where ';
	$ci=0;
	foreach ($columns as $col){
	if($ci)	{
		if(!(count($columns[$ci])>2 &&$columns[$ci][2]!='n'))
		$sw.=('lower('.$col[1].') like \'%'.strtolower($search).'%\'');
		
	}
	if($ci && count($columns)-1!=$ci)
		if(!(count($columns[$ci])>2 &&$columns[$ci][2]!='n'))$sw.=' or ';
	$ci++;
	}
	$search='&search='.$search;
	//exit($search);
}

$sql='select rownum r,g.* from '.$table.' g'.$sw;
//if(isset($_GET['search']))exit($sql);

$rows=$DBsql->fetch_all_array($sql);
$pageSize = 12;
$total=count($rows)== 0 ? 1 : count($rows);
//第一个0显示数字  第二个1显示概况 第三个显示下拉 第四个显示数字数量

pageft($total, $pageSize, 1, 1, 1, 5,$this_url.'?query=1'.'&querytab='.$querytab.$search);
$displaypg+=$firstcount;
$sql="select * from ($sql) where r > $firstcount and r <= $displaypg";
$rows=$DBsql->fetch_all_array($sql);



?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/validform.css" rel="stylesheet" type="text/css" />
<link href="public/page/css/css.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="js/Validform.js"></script>
<script language="javascript" type="text/javascript" src="js/public.js"></script>
<script language="javascript" type="text/javascript" src="js/date/WdatePicker.js"></script>
<style type="text/css">
.highlight {
	background: #FBF8E2;
}
</style>
<script language='javascript'>
var flag=false;
	function sltItem(e){
		if(e.checked){
			document.getElementById("hidd").value+=",";
			document.getElementById("hidd").value+=e.value;
		}else{
			var str=document.getElementById("hidd").value;
			var checkValu=","+e.value;
			var valu=str.replace(checkValu,"");
			document.getElementById("hidd").value=valu;
		}
	}
	function setselectstate(){
		   if(flag){
			   var $aray = document.getElementsByName("selectID");
			   for(var i=0;i<$aray.length;i++){
						$aray[i].checked = false;
				}
			   flag=false;
		   }else{
			   var $aray = document.getElementsByName("selectID");
			   for(var i=0;i<$aray.length;i++){
						$aray[i].checked = true;
				}
				flag=true;
		   }
		   sltAll();
		}
	function sltAll(){
		var $aray = document.getElementsByName("selectID");
		var $str="";
		var sub=",";
		for(var i=0;i<$aray.length;i++){
			if($aray[i].checked){
				$str+=sub+$aray[i].value;
			}
		}
		if($str==","){
			$("#hidd").val("");
		}else{
			$("#hidd").val($str);
		}
	}
	function delChecked(){
		var id=$('#hidd').val();
		if(id==""){
			alert('请选择要处理条目');
		}else{
			sn=id.substr(1,id.length);
			delRow(sn);
		}
	}
		function chuliChecked(){
		var id=$('#hidd').val();
		if(id==""){
			alert('请选择要审核条目');
		}else{
			sn=id.substr(1,id.length);
			chuli(sn);
		}
	}
	//新建警员
	function POP(popDiv){
		POPdiv(popDiv);
		$('#add').focus();
	}
	$(function()
	{
		$('#List tr:gt(0):not(:last)').hover(
		function(){
		$('#List tr td').removeClass("highlight");
		$(this).find('td').addClass("highlight");
		});
	});
	//修改警员信息
	function editRow(rowId){
		$('#upuser #sn').val(rowId);
		$.ajax({
			type:'POST',
			url:'fee.php',
			data:'act=select&sn='+rowId+'&query='+<?php echo $query?>,
			dataType:'json',
			beforeSend:function(){
			},
			success:function(data){
				if(data!=null)$.each( data, function(i, p){if(isNaN(i))$('#UPdiv').find('#'+i).val(p);});
			},
			error:function(){
				alert('服务器繁忙！');
			},
			complete:function(){
				POPdiv('UPdiv');
				$('#up').focus();	
			}
		});
	}
	//删除区号信息
	function delRow(rowId){
		if(!confirm('您确定删除该用户信息吗？')){
			return false;
		}
		$.ajax({
			type:'POST',
			url:'fee.php',
			data:'act=del&sn='+rowId+'&query='+<?php echo $query?>,
			success:function(data){
				if(data=='y'){
					$.Showmsg('删除成功！');
					setTimeout(function(){
					$.Hidemsg();
					window.location.reload();
				},1000);
				}else{
					$.Showmsg('删除失败！');
				}
			}	
		});
	}
	//处理警告信息
	function chuli(rowId){
		$.ajax({
			type:'POST',
			url:'fee.php',
			data:'act=chuli&sn='+rowId+'&query='+<?php echo $query?>,
			success:function(data){
				if(data=='y'){
					$.Showmsg('审核成功！');
					setTimeout(function(){
					$.Hidemsg();
					window.location.reload();
				},1000);
				}else{
					$.Showmsg('审核失败！');
				}
			}	
		});
	}	
	$(function(){
		$("#adduser").Validform({
			 tiptype:2,
			   ajaxurl:"fee.php?act=add"+'&query='+<?php echo $query?>,
			   callback:function(data){
					if(data.status=="y"){
						//$.Showmsg(data.info);
						setTimeout(function(){
							$.Hidemsg();
							window.location.reload();
						},1000);
					}else{
						$.Showmsg(data.info);
					}
			   }
		});
	$("#upuser").Validform({
		 tiptype:2,
		   ajaxurl:"fee.php?act=up"+'&query='+<?php echo $query?>,
		   callback:function(data){
				if(data.status=="y"){
					$.Showmsg(data.info);
					$.Showmsg(data.info);
					setTimeout(function(){
						$.Hidemsg();
						window.location.reload();
					},1000);
				}else{
					$.Showmsg(data.info);
				}
		   }
	});
});

</script>
<!--管理列表开始-->
<div class="manageTab">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="usrTab">
    <tr>
      <td width="8" height="25"><img src="images/user_01.jpg" height="25" width="8" /></td>
      <td style="background:#3980b2;" valign="middle" height="16" ><div class="use_righgDiv"><span>
          <input type="checkbox" id="checkall" name="" value="" onclick="setselectstate()" />
          全选</span>

          <span><img src="images/001.gif" height="14" width="14" /><a onclick="POP('POPdiv')" href="javascript:void(null)">新增</a></span>
          
          <?php 	foreach ($rbox as $i){    ?>
          <span><img src="images/<?php echo $rbox_array[$i][0] ?> height="14" width="14" />
          <a onclick="<?php echo $rbox_array[$i][1]?>"  href="javascript:void(null)"><?php echo $rbox_array[$i][2]?></a></span>
          <?php }?>

          <span><img src="images/010.gif" height="14" width="14" /><a onclick="delChecked()" href="javascript:void(null)">批量删除</a></span>
          
          <span></span>
          </div>
        <div class="use_leftDiv">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td  width="22"><img src="images/311.gif" height="16" width="16" /></td>
              <td align="left"><span class="tdTit"><?php echo $title ?></span></td>
            </tr>
          </table>
        </div></td>
      <td width="8" height="25"><img src="images/user_02.gif" height="25" width="10" /></td>
    </tr>
    <tr>
      <td style="background:#3980b2;" >&nbsp;</td>
      <td><table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" class="usrList" id="List">
          <tr>
            <td width="5%" class="td90b2">选择</td>
            
			  <?php 	foreach ($columns as $col){   ?>
               <td width="<?php ;echo 70/count($columns);?>%" class="td90b2">
			   <?php echo $col[0]?></td>
              <?php }?>

           <?php foreach ($rcol as $rci){ ?>
           <td width="8%" class="td90b2"><?php  echo $rclo_array[$rci][2]  ?></td>
            <?php }?>
            
         </tr>
          <?php if(count($rows)!=0){
          		foreach ($rows as $ros){
          	?>
          <tr id="List1">
            <td class="tdfff">
            	<input type='checkbox' onclick='sltItem(this)' name="selectID" class="STYLE2" value="<?php echo $ros[$columns[0][1]];?>" />
             </td>
             <?php 
			  $ci=0;
			  foreach ($columns as $col){?>
             <td class="tdfff"><?php echo $ros[$columns[$ci][1]];?></td>
             <?php $ci++;}?>
            
             <?php 
			  $ci=0;
			  foreach ($rclo_array as $rcol){?>
              <td class="tdfff"><div align="center"><img src="images/<?php  echo $rcol[0]; ?>" width="9" height="9" /><span class="STYLE1"> [</span><a href="javascript:void(null)" onclick="<?php  echo $rcol[1]; ?>('<?php echo $ros[$columns[0][1]];?>')"><?php  echo $rcol[2]; ?></a><span class="STYLE1">]</span></div></td>
             <?php $ci++;}?>
            
          </tr>
          <?php }}else{echo '暂无数据！';}?>
          <tr>
            <td colspan="<?php  echo (count($columns)+count($rclo_array)+1);?>" class="tdfff">&nbsp;</td>
          </tr>
        </table></td>
      <td style="background:#3980b2;">&nbsp;</td>
    </tr>
    <tr>
      <td height="28" width="8"><img src="images/user_03.gif" height="28" width="8" /></td>
      <td style="background:#3980b2;"><div class="green-black" style=""><?php echo $pagenav;?></div></td>
      <td height="28" width="8"><img src="images/user_04.gif" height="28" width="8" /></td>
    </tr>
  </table>
</div>
<!--管理列表结束-->
<input type="hidden" id='hidd' value="" />
<!--弹出层新建用户开始-->
<div id="POPdiv" class="POPdiv">
  <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('POPdiv')"><img src="images/ico_close.jpg" alt="关闭" /></a>增加</div>
  <div class="POPdiv_content">
    <form class="adduser" id="adduser">
      <table border="0" cellpadding="5" cellspacing="0">
           <?php foreach ($add_array as $add_a){ if($add_a<count($columns)){ ?> 
           <tr>
          <td width="100">
          	<p ><?php  echo $columns[$add_a][0];?>
              <label for="<?php  echo $columns[$add_a][1];?>">：</label>
            </p>
            </td>
          <td><input type="text" id="<?php  echo $columns[$add_a][1];?>" name='<?php  echo $columns[$add_a][1];?>' <?php if(count($columns[$add_a])>2 && $columns[$add_a][2]=='r') echo 'class="Wdate" onfocus="WdatePicker({dateFmt:\'yyyy-MM-dd HH:mm:ss\'})"';?> datatype="<?php if(count($columns[$add_a])>2) echo $columns[$add_a][2];?>" nullmsg="请输入<?php  echo $columns[$add_a][0];?>" errormsg='<?php if(count($columns[$add_a])>2) echo $waring_array[$columns[$add_a][2]];?>'/></td>
          <td><span class="Validform_checktip"><?php if(count($columns[$add_a])>2) echo $waring_array[$columns[$add_a][2]];else echo '请输入'.$columns[$add_a][0];?></span></td>
        </tr>
        <?php }}?>
         <tr>
          <td colspan="3"><input name="" id="add" type="submit" class="btnbg" value="添加" style="width:70px; margin-left:80px; color:#FFF" /></td>
        </tr>
      </table>
    </form>
  </div>
</div>
<!--弹出层新建用户结束--> 



<!--弹出层修改用户开始-->
<div id="UPdiv" class="POPdiv">
  <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('UPdiv')"><img src="images/ico_close.jpg" alt="关闭" /></a>修改信息</div>
  <div class="POPdiv_content">
    <form class="adduser" id="upuser">
	<input type='hidden' id='sn' name='sn' />
      <table border="0" cellpadding="5" cellspacing="0">
           <?php foreach ($add_array as $add_a){ if($add_a<count($columns)){ ?> 
           <tr>
          <td width="100">
          	<p ><?php  echo $columns[$add_a][0];?>
              <label for="<?php  echo $columns[$add_a][1];?>">：</label>
            </p>
            </td>
          <td><input type="text"  id="<?php  echo $columns[$add_a][1];?>" name='<?php  echo $columns[$add_a][1];?>' <?php if(count($columns[$add_a])>2 && $columns[$add_a][2]=='r') echo 'class="Wdate" onfocus="WdatePicker({dateFmt:\'yyyy-MM-dd HH:mm:ss\'})"';?> datatype="<?php if(count($columns[$add_a])>2) echo $columns[$add_a][2];?>" nullmsg="请输入<?php  echo $columns[$add_a][0];?>" errormsg='<?php if(count($columns[$add_a])>2) echo $waring_array[$columns[$add_a][2]];?>'/></td>
          <td><span class="Validform_checktip"><?php if(count($columns[$add_a])>2) echo $waring_array[$columns[$add_a][2]];else echo '请输入'.$columns[$add_a][0];?></span></td>
        </tr>
        <?php }}?>
         <tr>
          <td colspan="3"><input name="" id="add" type="submit" class="btnbg" value="修改" style="width:70px; margin-left:80px; color:#FFF" /></td>
        </tr>
      </table>
      <input type="hidden" id="hiddUp" name="hiddUp"/>
    </form>
  </div>
</div>
<!--弹出层修改用户结束--> 
<!--弹出层选择派出所开始-->
<div id="selectLocation" class="POPdiv">
  <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('selectLocation')"><img src="images/ico_close.jpg" alt="关闭" /></a>分组查看</div>
  <div class="POPdiv_content">
    <form id="Location" action="user.php" method="get">
      <table border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td width="80"><label for="selectID">选择派出所</label></td>
          <td><select id="selectID" name="selectID" onchange="groupSelect()">
              <option value="">全部</option>
            </select></td>
          <td><input type="hidden" id="departmentID" name="departmentID" value=""></td>
        </tr>
      </table>
    </form>
  </div>
</div>
<!--弹出层选择派出所结束-->